/* "Efficiency and water use: Dynamic effects of irrigation technology adoption"
by Micah Cameron-Harp and Nathan Hendricks

Code written by Micah Cameron-Harp
May 16th, 2024

This do file estimates the average and dynamic treatment effects for both 
	transitions using the Chaisemartin & D'Haultfoueille (2021) estimator.
	These results are used to create Table D.10 and Figures D.3, D.4, and D.5. 
*/

/* NOTE - Global macros for directories are created in the appendices_results.do 
	file which calls this individual .do file */
	
********************************************************************************
********** Flood to Center Pivot or LEPA ***************************************
********************************************************************************
	import delimited using "${dr_temp}/flood_cporlepa_prepped.csv", clear
	keep if inrange(wua_year, 1991, 2015) 

*Create quintiles of initial acre-feet withdrawals
xtile init_af_quint = init_af_used, nq(5)
*Set working directory where results will be savec
cd "$dr_temp"

foreach y in "af_used"  "acres_irr" "depth_applied" {
	did_multiplegt `y' wr_group wua_year treat_status, ///
					dynamic(22) average_effect robust_dynamic covariances ///
					longdiff_placebo placebo(12) jointtestplacebo breps(100) cluster(wr_group) ///
					controls(jan_april_mean_ppt may_sep_mean_ppt jan_april_mean_et0_elev may_sep_mean_et0_elev) ///
					trends_nonparam(init_af_quint) ///
					save_results(didl_flood_cplepa_`y')				
}	

********************************************************************************
***************** Center Pivot to LEPA *****************************************
********************************************************************************
import delimited using "${dr_temp}\cp_lepa_prepped.csv", clear
*Create quintiles of initial acre-feet withdrawals
	xtile init_af_quint = init_af_used, nq(5)
	*Set working directory where results will be savec
	cd "$dr_output_tables"
	foreach y in "af_used"  "acres_irr" "depth_applied" {
		did_multiplegt `y' wr_group wua_year treat_status, ///
						dynamic(22) average_effect robust_dynamic covariances ///
						longdiff_placebo placebo(14) jointtestplacebo breps(100) cluster(wr_group) ///
						controls(jan_april_mean_ppt may_sep_mean_ppt jan_april_mean_et0_elev may_sep_mean_et0_elev) ///
						trends_nonparam(init_af_quint) ///
						save_results(didl_cp_lepa_`y')
						
	}